<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <h1 id="h1"></h1>
    <script>
        function getDateDiff(dateTimeStamp){
            var minute = 1000 * 60;
            var hour = minute * 60;
            var day = hour * 24;
            var halfamonth = day * 15;
            var month = day * 30;
            var now = new Date().getTime();
            var diffValue = now - dateTimeStamp*1000;
            console.log(now);
            console.log(dateTimeStamp);
            console.log(diffValue);
            if(diffValue < 0){return;}
            var monthC =diffValue/month;
            var weekC =diffValue/(7*day);
            var dayC =diffValue/day;
            var hourC =diffValue/hour;
            var minC =diffValue/minute;
            console.log(monthC+"月"+weekC+"周"+dayC+"天"+hourC+"时"+minC+"分");
            if(monthC>=1){
                console.log(parseInt(monthC) + "月前");
                function less(m){return m<10?'0'+m:m }
                var showTime = new Date(dateTimeStamp*1000);
                var showYear = showTime.getFullYear();
                var showMonth = showTime.getMonth()+1;
                var showDate = showTime.getDate();
                var showHours = showTime.getHours();
                var showMinutes = showTime.getMinutes();
                var showSeconds = showTime.getSeconds();
                console.log(showYear+'-'+less(showMonth)+'-'+less(showDate)+' '+less(showHours)+':'+less(showMinutes));
            }
            else if(weekC>=1){
                console.log(parseInt(weekC) + "周前");
            }
            else if(dayC>=1){
                console.log(parseInt(dayC) +"天前");
            }
            else if(hourC>=1){
                console.log(parseInt(hourC) +"小时前");
            }
            else if(minC>=1){
                console.log(parseInt(minC) +"分钟前");
            }else{
                console.log("刚刚");
            }
    }
    // var time=document.getElementById("h1").value;
    // console.log(time);
    getDateDiff(1552203000);
    </script>
</body>
</html>